#pragma once

#include <iostream>
#include <sys/epoll.h>
#include "Log.hpp"
#include "Common.hpp"

using namespace MyLog;

class Epoller
{
public:
    Epoller() : _epfd(-1)
    {
        _epfd = epoll_create(128);
        if (_epfd < 0)
        {
            LOG(Loglevel::FATAL) << "epoll_create error...";
            exit(EPOLL_CREATE_ERROR);
        }
        LOG(Loglevel::INFO) << "epoll_create success...";
    }

    void AddEvent(int sockfd, uint32_t event)
    {
        struct epoll_event ev;
        ev.data.fd = sockfd;
        ev.events = event;
        int n = epoll_ctl(_epfd, EPOLL_CTL_ADD, sockfd, &ev);
        if (n < 0)
        {
            LOG(Loglevel::ERROR) << "epoll_clt error...";
            return;
        }
        LOG(Loglevel::INFO) << "epoll_clt success..." << sockfd;
    }

    void DelEvent()
    {
    }

    void ModEvent()
    {
    }

    void Wait()
    {
    }

    ~Epoller()
    {
        if (_epfd >= 0)
        {
            close(_epfd);
        }
    }

private:
    int _epfd;
};